// pages/drugDetail/drugDetail.js
import Toast from '@vant/weapp/toast/toast';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    from: '',
    drugDetail: {}
  },

  async getDrugDetail(id) {
    const res = await app.call({
      path: '/drug/drugDetail?id=' + id,
      method: 'GET'
    })
    console.log(res)
    if (res.code === 0) {
      console.log(res.data)
      this.setData({
        drugDetail: res.data.drugDetail
      })
    } else {
      Toast.fail(res.errorMsg);
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log("options>>", options);
    this.setData({
      id: options.id,
      from: options.from
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDrugDetail(this.data.id);
  },

  gotoEditDrug() {
    wx.navigateTo({
      url: '/pages/editDrug/editDrug?from=drugDetail&id=' + this.data.drugDetail.id,
    })
  },

  catImg(event) {
    wx.previewImage({
      current: this.data.drugDetail.img,
      urls: [this.data.drugDetail.img]
    })
  }
})